package app.qrcode.browser.hearttoheart.ui.dashboard

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import app.qrcode.browser.hearttoheart.R
import app.qrcode.browser.hearttoheart.adapters.*
import app.qrcode.browser.hearttoheart.databinding.FragmentDashboardBinding

class DashboardFragment : Fragment() {

    private var _binding: FragmentDashboardBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    private val dashList = ArrayList<Dash>()

    private val dashAdapter by lazy { DashAdapter() }

    private val msgList = ArrayList<Msg>()

    private val msgAdapter by lazy { MsgAdapter() }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val dashboardViewModel =
            ViewModelProvider(this).get(DashboardViewModel::class.java)

        _binding = FragmentDashboardBinding.inflate(inflater, container, false)
        val root: View = binding.root
        initRecyclerView()
        return root
    }


    fun initRecyclerView() {
        initDashList()
        initMsgList()
    }

    fun initDashList() {
        val dashLayoutManager = LinearLayoutManager(context)
        binding.dashList.layoutManager = dashLayoutManager
        binding.dashList.adapter = dashAdapter
        dashList.add(Dash("新的朋友", R.mipmap.newfridend))
        dashList.add(Dash("教师组", R.mipmap.teachergroup))
        dashList.add(Dash("学生组", R.mipmap.studentgroup))
        dashList.add(Dash("群聊", R.mipmap.grouptalk))
        dashList.add(Dash("标签", R.mipmap.sign))
        dashList.add(Dash("公众号", R.mipmap.publicaccount))
        dashAdapter.updateList(dashList)
    }

    fun initMsgList() {
        val msgLayoutManager = LinearLayoutManager(context)
        binding.msgList.layoutManager = msgLayoutManager
        binding.msgList.adapter = msgAdapter
        msgList.add(Msg("@我的", R.mipmap.mine, null, null))
        msgList.add(Msg("评论", R.mipmap.comments, null, R.mipmap.message3))
        msgList.add(Msg("赞", R.mipmap.likes, null, null))
        msgList.add(Msg("未关注人消息", R.mipmap.weiguanzhu, "杨老师 发来了新消息", R.mipmap.message15))
        msgList.add(Msg("戴老师", R.mipmap.one, "发来了新消息", R.mipmap.message11))
        msgAdapter.updateList(msgList)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}